
from django.core.mail import send_mail
from celery_tasks.main import celery_app
from django.conf import settings

@celery_app.task(name='sendemail')
def sendemail(to_email,verify_url):
    '''
    def send_mail(subject, message, from_email, recipient_list,
              fail_silently=False, auth_user=None, auth_password=None,
              connection=None, html_message=None):
    """
    Easy wrapper for sending a single message to a recipient list. All members
    of the recipient list will see the other recipients in the 'To' field.

    If auth_user is None, use the EMAIL_HOST_USER setting.
    If auth_password is None, use the EMAIL_HOST_PASSWORD setting.

    Note: The API for this method is frozen. New code wanting to extend the
    functionality should use the EmailMessage class directly.
    """

    '''
    subject = "KonoDioda"
    # 发送内容:
    html_message = '<p>我不做人拉！JOJO</p>' \
                   '<p>WRYYYYYYYYYY。</p>' \
                   '<img src="https://imgsa.baidu.com/forum/w%3D580/sign=c2f1167442086e066aa83f4332097b5a/ee15212ac65c1038292b4487bc119313b17e89e7.jpg" alt="dio">' \
                    '<a href=' + verify_url +'></a>'
    # '<p><a href="%s">%s<a></p>' % (to_email, verify_url, verify_url)  不能用 报错 unsupported format character 'D' (0x44) at index 80

    send_mail(
        subject=subject,
        message='',
        from_email=settings.EMAIL_FROM,
        recipient_list=[to_email],
        html_message=html_message
    )